local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill {
  name = "rmt__zhangnan",
  tags = {DIY.ReadySkill},
}

Fk:loadTranslationTable{
  ["rmt__zhangnan"] = "障南",
  [":rmt__zhangnan"] = "<a href='diy_ready_skill'>蓄势技</a>，座次或攻击范围小于你的角色造成伤害时，你可以防止之。此技能行置期间，"..
  "你视为拥有技能〖锋西〗。",

  ["#rmt__zhangnan-invoke"] = "障南：是否防止 %src 对 %dest 造成的 %arg 点伤害？",

  ["$rmt__zhangnan1"] = "柱石七尺，鼠辈岂可逾越？",
  ["$rmt__zhangnan2"] = "摧城破敌，吴贼不足挂齿。",
}

skel:addEffect(fk.DamageCaused, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target and player:hasSkill(skel.name) and
      not target.dead and (target.seat < player.seat or target:getAttackRange() < player:getAttackRange())
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name,
    prompt = "#rmt__zhangnan-invoke:"..target.id..":"..data.to.id..":"..data.damage }) then
      event:setCostData(self, {tos = {data.from, data.to}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    data:preventDamage()
  end,
})

skel:addEffect(DIY.SkillReadyStart, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data and data.skill.name == skel.name
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "rmt__fengxi", nil, true, false)
  end,
})


skel:addEffect(DIY.SkillReadyFinish, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data and data.skill.name == skel.name
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "-rmt__fengxi", nil, true, false)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:handleAddLoseSkills(player, "-rmt__fengxi", nil, true, false)
end)

return skel
